/*     */ package com.wgcloud.controller;
/*     */ 
/*     */ import cn.hutool.json.JSONObject;
/*     */ import cn.hutool.json.JSONUtil;
/*     */ import com.github.pagehelper.PageInfo;
/*     */ import com.wgcloud.entity.FileSafe;
/*     */ import com.wgcloud.entity.SystemInfo;
/*     */ import com.wgcloud.service.FileSafeService;
/*     */ import com.wgcloud.service.LogInfoService;
/*     */ import com.wgcloud.service.SystemInfoService;
/*     */ import com.wgcloud.util.HostUtil;
/*     */ import com.wgcloud.util.PageUtil;
/*     */ import com.wgcloud.util.ResDataUtils;
/*     */ import com.wgcloud.util.TokenUtils;
/*     */ import com.wgcloud.util.license.LicenseUtil;
/*     */ import com.wgcloud.util.staticvar.StaticKeys;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.annotation.Resource;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.ui.Model;
/*     */ import org.springframework.web.bind.annotation.RequestBody;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/fileSafe"})
/*     */ public class FileSafeController
/*     */ {
/*  47 */   private static final Logger logger = LoggerFactory.getLogger(com.wgcloud.controller.FileSafeController.class);
/*     */ 
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private FileSafeService fileSafeService;
/*     */ 
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private LogInfoService logInfoService;
/*     */ 
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private SystemInfoService systemInfoService;
/*     */ 
/*     */ 
/*     */   
/*     */   @Autowired
/*     */   private TokenUtils tokenUtils;
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @ResponseBody
/*     */   @RequestMapping({"agentList"})
/*     */   public String agentList(@RequestBody String paramBean) {
/*  75 */     JSONObject agentJsonObject = (JSONObject)JSONUtil.parse(paramBean);
/*  76 */     if (!this.tokenUtils.checkAgentToken(agentJsonObject)) {
/*  77 */       logger.error("token is error");
/*  78 */       return ResDataUtils.resetErrorJson("token is error");
/*     */     } 
/*  80 */     Map<String, Object> params = new HashMap<>();
/*  81 */     if (null == agentJsonObject.get("hostname") || StringUtils.isEmpty(agentJsonObject.get("hostname").toString())) {
/*  82 */       return "";
/*     */     }
/*  84 */     params.put("hostname", agentJsonObject.get("hostname").toString());
/*     */     try {
/*  86 */       params.put("active", "1");
/*  87 */       List<FileSafe> FileSafeList = this.fileSafeService.selectAllByParams(params);
/*  88 */       return ResDataUtils.resetSuccessJson(FileSafeList);
/*  89 */     } catch (Exception e) {
/*  90 */       logger.error("agent获取文件防篡改信息错误", e);
/*  91 */       this.logInfoService.save("agent获取文件防篡改信息错误", e.toString(), "1");
/*  92 */       return ResDataUtils.resetErrorJson(e.toString());
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"list"})
/*     */   public String FileSafeList(FileSafe fileSafe, Model model, HttpServletRequest request) {
/* 105 */     Map<String, Object> params = new HashMap<>();
/*     */     
/*     */     try {
/* 108 */       LicenseUtil.maxLicense_10(model, request);
/*     */ 
/*     */       
/* 111 */       StringBuffer url = new StringBuffer();
/* 112 */       String hostname = null;
/* 113 */       if (!StringUtils.isEmpty(fileSafe.getHostname())) {
/* 114 */         hostname = fileSafe.getHostname();
/* 115 */         params.put("hostname", hostname.trim());
/* 116 */         url.append("&hostname=").append(hostname);
/*     */       } 
/* 118 */       if (!StringUtils.isEmpty(fileSafe.getState())) {
/* 119 */         params.put("state", fileSafe.getState());
/* 120 */         url.append("&state=").append(fileSafe.getState());
/*     */       } 
/* 122 */       PageInfo<FileSafe> pageInfo = this.fileSafeService.selectByParams(params, fileSafe.getPage().intValue(), fileSafe.getPageSize().intValue());
/* 123 */       for (FileSafe FileSafe1 : pageInfo.getList()) {
/* 124 */         FileSafe1.setHostname(FileSafe1.getHostname() + HostUtil.addRemark(FileSafe1.getHostname()));
/*     */       }
/* 126 */       PageUtil.initPageNumber(pageInfo, model);
/* 127 */       model.addAttribute("pageUrl", "/fileSafe/list?1=1" + url.toString());
/* 128 */       model.addAttribute("page", pageInfo);
/* 129 */       model.addAttribute("fileSafe", fileSafe);
/* 130 */     } catch (Exception e) {
/* 131 */       logger.error("查询文件防篡改信息错误", e);
/* 132 */       this.logInfoService.save("查询文件防篡改信息错误", e.toString(), "1");
/*     */     } 
/*     */     
/* 135 */     return "fileSafe/list";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"save"})
/*     */   public String saveFileSafe(FileSafe fileSafe, Model model, HttpServletRequest request) {
/* 149 */     String errorMsg = "保存文件防篡改信息错误";
/*     */     try {
/* 151 */       if (StringUtils.isEmpty(fileSafe.getId())) {
/* 152 */         this.fileSafeService.save(fileSafe);
/*     */       } else {
/* 154 */         this.fileSafeService.updateById(fileSafe);
/*     */       } 
/* 156 */     } catch (Exception e) {
/* 157 */       logger.error(errorMsg, e);
/* 158 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 160 */     return "redirect:/fileSafe/list";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"saveBatch"})
/*     */   public String saveBatchFileSafe(FileSafe fileSafe, Model model, HttpServletRequest request) {
/* 173 */     String errorMsg = "批量保存文件防篡改信息错误";
/*     */     try {
/* 175 */       String[] hostnames = request.getParameterValues("hostnames");
/* 176 */       if (null == hostnames || hostnames.length < 1) {
/* 177 */         return "redirect:/fileSafe/list";
/*     */       }
/* 179 */       for (String selectedHost : hostnames) {
/* 180 */         fileSafe.setHostname(selectedHost);
/* 181 */         this.fileSafeService.save(fileSafe);
/*     */       } 
/* 183 */     } catch (Exception e) {
/* 184 */       logger.error(errorMsg, e);
/* 185 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 187 */     return "redirect:/fileSafe/list";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"edit"})
/*     */   public String edit(Model model, HttpServletRequest request) {
/* 199 */     String errorMsg = "添加文件防篡改信息错误";
/* 200 */     String id = request.getParameter("id");
/* 201 */     FileSafe fileSafe = new FileSafe();
/*     */     try {
/* 203 */       List<SystemInfo> systemInfoList = this.systemInfoService.selectAllByParams(new HashMap<>());
/* 204 */       model.addAttribute("systemInfoList", systemInfoList);
/* 205 */       if (StringUtils.isEmpty(id)) {
/* 206 */         model.addAttribute("fileSafe", fileSafe);
/*     */ 
/*     */         
/* 209 */         Map<String, Object> params = new HashMap<>();
/* 210 */         int dbSize = this.fileSafeService.countByParams(params);
/* 211 */         if (dbSize >= 10 && !StaticKeys.LICENSE_STATE.equals("1")) {
/* 212 */           return "redirect:/fileSafe/list?liceFlage=1";
/*     */         }
/*     */ 
/*     */         
/* 216 */         return "fileSafe/add";
/*     */       } 
/* 218 */       fileSafe = this.fileSafeService.selectById(id);
/* 219 */       model.addAttribute("fileSafe", fileSafe);
/* 220 */     } catch (Exception e) {
/* 221 */       logger.error(errorMsg, e);
/* 222 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 224 */     return "fileSafe/add";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"editBatch"})
/*     */   public String editBatch(Model model, HttpServletRequest request) {
/* 236 */     String errorMsg = "批量添加文件防篡改信息错误";
/* 237 */     FileSafe fileSafe = new FileSafe();
/*     */     try {
/* 239 */       List<SystemInfo> systemInfoList = this.systemInfoService.selectAllByParams(new HashMap<>());
/* 240 */       model.addAttribute("systemInfoList", systemInfoList);
/* 241 */       model.addAttribute("fileSafe", fileSafe);
/*     */ 
/*     */       
/* 244 */       Map<String, Object> params = new HashMap<>();
/* 245 */       int dbSize = this.fileSafeService.countByParams(params);
/* 246 */       if (dbSize >= 10 && !StaticKeys.LICENSE_STATE.equals("1")) {
/* 247 */         return "redirect:/fileSafe/list?liceFlage=1";
/*     */       
/*     */       }
/*     */     }
/* 251 */     catch (Exception e) {
/* 252 */       logger.error(errorMsg, e);
/* 253 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 255 */     return "fileSafe/addBatch";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"del"})
/*     */   public String delete(Model model, HttpServletRequest request, RedirectAttributes redirectAttributes) {
/* 270 */     String errorMsg = "删除文件防篡改监测信息错误";
/* 271 */     FileSafe fileSafe = new FileSafe();
/*     */     try {
/* 273 */       if (!StringUtils.isEmpty(request.getParameter("id"))) {
/* 274 */         String[] ids = request.getParameter("id").split(",");
/* 275 */         for (String id : ids) {
/* 276 */           fileSafe = this.fileSafeService.selectById(id);
/* 277 */           this.logInfoService.save("删除文件防篡改监测信息：" + fileSafe.getHostname(), "删除文件防篡改监测信息：" + fileSafe.getHostname() + "：" + fileSafe.getFileName() + "，" + fileSafe.getFilePath(), "0");
/*     */         } 
/* 279 */         this.fileSafeService.deleteById(ids);
/*     */       } 
/* 281 */     } catch (Exception e) {
/* 282 */       logger.error(errorMsg, e);
/* 283 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/*     */     
/* 286 */     return "redirect:/fileSafe/list";
/*     */   }
/*     */ }


/* Location:              /Users/zhangyongxin/soft-install/wgcloud/wgcloud-v3.3.5/server/bank/wgcloud-server-release.jar!/BOOT-INF/classes/com/wgcloud/controller/FileSafeController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */